home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / include / util / nsTimer.h next >
C/C++ Source or Header  |  2006-05-08  |  6KB  |  207 lines

  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Mozilla Public License Version
  6.  * 1.1 (the "License"); you may not use this file except in compliance with
  7.  * the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/MPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is Mozilla Communicator client code.
  16.  *
  17.  * The Initial Developer of the Original Code is
  18.  * Netscape Communications Corporation.
  19.  * Portions created by the Initial Developer are Copyright (C) 1998
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *
  24.  * Alternatively, the contents of this file may be used under the terms of
  25.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  26.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27.  * in which case the provisions of the GPL or the LGPL are applicable instead
  28.  * of those above. If you wish to allow use of your version of this file only
  29.  * under the terms of either the GPL or the LGPL, and not to allow others to
  30.  * use your version of this file under the terms of the MPL, indicate your
  31.  * decision by deleting the provisions above and replace them with the notice
  32.  * and other provisions required by the GPL or the LGPL. If you do not delete
  33.  * the provisions above, a recipient may use your version of this file under
  34.  * the terms of any one of the MPL, the GPL or the LGPL.
  35.  *
  36.  * ***** END LICENSE BLOCK ***** */
  37.  
  38. #ifndef __NSTIMER_H
  39. #define __NSTIMER_H
  40.  
  41. #ifdef MOZ_PERF_METRICS
  42.  
  43. #include "stopwatch.h"
  44.  
  45. class nsStackBasedTimer 
  46. {
  47. public:
  48.   nsStackBasedTimer(Stopwatch* aStopwatch) { sw = aStopwatch; }
  49.   ~nsStackBasedTimer() { if (sw) sw->Stop(); }
  50.  
  51.   void Start(PRBool aReset) { if (sw) sw->Start(aReset); }
  52.   void Stop(void) { if (sw) sw->Stop(); }
  53.   void Reset(void) { if (sw) sw->Reset(); }
  54.   void SaveState(void) { if (sw) sw->SaveState(); }
  55.   void RestoreState(void) { if (sw) sw->RestoreState(); }
  56.   void Print(void) { if (sw) sw->Print(); }
  57.   
  58. private:
  59.   Stopwatch* sw;
  60. };
  61.  
  62. // This should be set from preferences at runtime.  For now, make it a compile time flag.
  63. #define ENABLE_DEBUG_OUTPUT PR_FALSE
  64.  
  65. // Uncomment and re-build to use the Mac Instrumentation SDK on a Mac.
  66. // #define MOZ_TIMER_USE_MAC_ISDK
  67.  
  68. // Uncomment and re-build to use Quantify on Windows
  69. // #define MOZ_TIMER_USE_QUANTIFY
  70.  
  71. // Timer macros for the Mac
  72. #ifdef XP_MAC
  73.  
  74. #ifdef MOZ_TIMER_USE_MAC_ISDK
  75.  
  76. #include "InstrumentationHelpers.h"
  77. #  define MOZ_TIMER_DECLARE(name)  
  78. #  define MOZ_TIMER_CREATE(name)   \
  79.   static InstTraceClassRef name = 0;  StInstrumentationLog __traceLog("Creating name..."), name)
  80.  
  81. #  define MOZ_TIMER_RESET(name, msg)
  82. #  define MOZ_TIMER_START(name, msg)
  83. #  define MOZ_TIMER_STOP(name, msg)
  84. #  define MOZ_TIMER_SAVE(name, msg)
  85. #  define MOZ_TIMER_RESTORE(name, msg)
  86. #  define MOZ_TIMER_LOG(msg) \
  87.   do { __traceLog.LogMiddleEvent(); } while(0)
  88.  
  89. #  define MOZ_TIMER_DEBUGLOG(msg) \
  90.   if (ENABLE_DEBUG_OUTPUT) printf msg
  91.  
  92. #  define MOZ_TIMER_MACISDK_LOGDATA(msg, data) \
  93.   do { traceLog.LogMiddleEventWithData((msg), (data)); } while (0)
  94.  
  95. #else
  96.  
  97. #define MOZ_TIMER_USE_STOPWATCH
  98.  
  99. #endif  // MOZ_TIMER_USE_MAC_ISDK
  100.  
  101. #endif  // XP_MAC
  102.  
  103.  
  104. // Timer macros for Windows
  105. #ifdef XP_WIN
  106.  
  107. #ifdef MOZ_TIMER_USE_QUANTIFY
  108.  
  109. #include "pure.h"
  110. #include "prprf.h"
  111.  
  112. #  define MOZ_TIMER_DECLARE(name)
  113. #  define MOZ_TIMER_CREATE(name)
  114. #  define MOZ_TIMER_RESET(name)  \
  115.   QuantifyClearData()
  116.  
  117. #  define MOZ_TIMER_START(name)  \
  118.   QuantifyStartRecordingData()
  119.   
  120. #  define MOZ_TIMER_STOP(name) \
  121.   QuantifyStopRecordingData()
  122.  
  123. #  define MOZ_TIMER_SAVE(name)
  124. #  define MOZ_TIMER_RESTORE(name)
  125.  
  126. #  define MOZ_TIMER_PRINT(name)
  127.  
  128. #  define MOZ_TIMER_LOG(msg)    \
  129. do {                            \
  130.   char* str = PR_smprintf msg;  \
  131.   QuantifyAddAnnotation(str);   \
  132.   PR_smprintf_free(str);        \
  133. } while (0)
  134.  
  135. #  define MOZ_TIMER_DEBUGLOG(msg) \
  136.   if (ENABLE_DEBUG_OUTPUT) printf msg
  137.  
  138. #  define MOZ_TIMER_MACISDK_LOGDATA(msg, data)
  139.  
  140. #else
  141.  
  142. #define MOZ_TIMER_USE_STOPWATCH
  143.  
  144. #endif  // MOZ_TIMER_USE_QUANTIFY
  145.  
  146. #endif  // XP_WIN
  147.  
  148. // Timer macros for Unix
  149. #ifdef XP_UNIX
  150.  
  151. #define MOZ_TIMER_USE_STOPWATCH
  152.  
  153. #endif  // XP_UNIX
  154.  
  155. #ifdef MOZ_TIMER_USE_STOPWATCH
  156.  
  157. #  define MOZ_TIMER_DECLARE(name)  \
  158.   Stopwatch name;
  159.  
  160. #  define MOZ_TIMER_CREATE(name)    \
  161.   static Stopwatch __sw_name;  nsStackBasedTimer name(&__sw_name)
  162.  
  163. #  define MOZ_TIMER_RESET(name)  \
  164.   name.Reset();
  165.  
  166. #  define MOZ_TIMER_START(name)  \
  167.   name.Start(PR_FALSE);
  168.  
  169. #  define MOZ_TIMER_STOP(name) \
  170.   name.Stop();
  171.  
  172. #  define MOZ_TIMER_SAVE(name) \
  173.   name.SaveState();
  174.  
  175. #  define MOZ_TIMER_RESTORE(name)  \
  176.   name.RestoreState();
  177.  
  178. #  define MOZ_TIMER_PRINT(name)   \
  179.   name.Print();
  180.  
  181. #  define MOZ_TIMER_LOG(msg)  \
  182.   printf msg
  183.  
  184. #  define MOZ_TIMER_DEBUGLOG(msg) \
  185.   if (ENABLE_DEBUG_OUTPUT) printf msg
  186.  
  187. #  define MOZ_TIMER_MACISDK_LOGDATA(msg, data)
  188.  
  189. #endif // MOZ_TIMER_USE_STOPWATCH
  190.  
  191. #else
  192. #  define MOZ_TIMER_DECLARE(name)
  193. #  define MOZ_TIMER_CREATE(name)
  194. #  define MOZ_TIMER_RESET(name)
  195. #  define MOZ_TIMER_START(name)
  196. #  define MOZ_TIMER_STOP(name)
  197. #  define MOZ_TIMER_SAVE(name)
  198. #  define MOZ_TIMER_RESTORE(name)
  199. #  define MOZ_TIMER_PRINT(name)
  200. #  define MOZ_TIMER_LOG(msg)
  201. #  define MOZ_TIMER_DEBUGLOG(msg)
  202. #  define MOZ_TIMER_MACISDK_LOGDATA(msg, data)
  203. #endif  // MOZ_PERF_METRICS
  204.  
  205. #endif  // __NSTIMER_H
  206.  
  207.